

-- 1. 使用两种方式打印信息：hello sql 
declare @str nvarchar(80)='hello sql'
print @str

raiserror ('hello sql',0,1)with nowait
-- 2. 声明变量i，赋值为100，然后打印
declare @i int =100
print @i

-- 3. 声明变量str，并赋值为：sql is very easy，然后打印
 declare @str varchar(80)='sql is very easy'
 print @str

-- 4. 为赵云执行开卡操作，赵云身份证：420107199904054233，手机号：13554785965，新开卡号：6225125478544588，使用变量的方式

select * from BankCard
declare @AccountCode varchar(18)='420107199904054233'
select * from AccountInfo where AccountCode= @AccountCode 

declare @CarNo varchar(19)='6225125478544588'
insert into BankCard (CardNo,AccountId,CardPwd,CardBalance,CardState,CardTime)values(@CarNo,4,123456,10000,1,getdate())
insert into CardExchange(CardNo,MoneyInBank,MoneyOutBank,ExchangeTime)values(@CarNo,10000,0,getdate())

-- 5. 需要查找出张飞的银行卡号和余额，张飞身份证：420107199602034138，使用连接查询和变量的方式

declare @AccountCode varchar(18)='420107199602034138'
select a.RealName,b.CardNo,b.CardBalance from AccountInfo a 
left join  BankCard b on a.AccountId=b.AccountId
where AccountCode=@AccountCode

declare @AccountCode varchar(18)='420107199602034138'
select CardNo,CardBalance from BankCard where AccountId in(select AccountId from AccountInfo where AccountCode=@AccountCode)